package day1104;

import java.util.Random;
import java.util.Scanner;
import java.util.function.Predicate;

/**
 * @author Mr.ma
 * @since 2022/11/4 14:33
 * Predicate：断言型函数式接口，boolean test(T t)
 **/
public class TestPredicate {
    public static void main(String[] args) {
        System.out.println("请输入你猜测的数字(0-10)：");
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        doSome(i, (x) -> {
            Random random = new Random();
            int i1 = random.nextInt(10);
            System.out.println("正确答案为：" + i1);
            return x.equals(i1);
        });
    }
    public static void doSome(Integer i, Predicate<Integer> predicate){
        boolean test = predicate.test(i);
        if (test){
            System.out.println("猜对了，牛批！");
        } else {
            System.out.println("猜错了，别灰心，反正你也没有下一次机会了");
        }
    }
}
